package com.xxxy.ljh.myapplication;

import android.os.Bundle;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.xxxy.ljh.myapplication.Adapter.ViewPagerAdapter;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    TabLayout tabLayout;
    ViewPager2 viewPager2;
    ViewPagerAdapter viewPagerAdapter;
    Button btnLogin;
    String [] titles = {"主页", "社团", "活动","我的"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        init();

    }
    private void init() {
        // 初始化TabLayout和ViewPager2组件
        tabLayout = findViewById(R.id.tabLayout);
        viewPager2 = findViewById(R.id.ViewPager2);
        // 创建并设置ViewPager2的适配器
        viewPagerAdapter = new ViewPagerAdapter(this, List.of(titles));
        viewPager2.setAdapter(viewPagerAdapter);
        // 建立TabLayout与ViewPager2的联动关系，配置每个标签页的显示文本
        new TabLayoutMediator(tabLayout, viewPager2, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int i) {
                tab.setText(titles[i]);
            }
        }).attach();

    }

    public ViewPager2 getViewPager2() {
        return viewPager2;
    }



}